package com.example.boxuegu;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.boxuegu.DengZhu.MyDenglu;

public class myinfo {
//
//    private LinearLayout ll_head;
//    public ImageView iv_head_icon;
//    private RelativeLayout rl_course_history;
//    private RelativeLayout rl_user_history;
//    private TextView tv_user_name;
//    private Activity mContext;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_myinfo);
//        init();
//
//    }
//    /*
//    * 获取界面控件*/
//    private void init() {
//        ll_head = (LinearLayout) findViewById(R.id.ll_head);
//        iv_head_icon = (ImageView) findViewById(R.id.iv_head_icon);
//        rl_course_history = (RelativeLayout) findViewById(R.id.rl_course_history);
//        rl_user_history = (RelativeLayout) findViewById(R.id.rl_user_history);
//        tv_user_name = (TextView) findViewById(R.id.tv_user_name);
//        setLoginParams(readLogStatus());
//        ll_head.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                //判断是否登录
//                if(readLogStatus()){
//                    //已经登陆就跳转到个人资料界面
//                }else{
//                    //未登录跳转到登陆界面
//                    Toast.makeText(mContext,"您还未登录，请先登录",Toast.LENGTH_SHORT).show();
//                    Intent intent = new Intent(mContext, MyDenglu.class);
//                    mContext.startActivityForResult(intent,1);
//                }
//            }
//        });
//        rl_course_history.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(readLogStatus()){
//                    //已经登陆就跳转到播放记录界面
//                }else{
//                    //未登录跳转到登陆界面
//                    Toast.makeText(mContext,"您还未登录，请先登录",Toast.LENGTH_SHORT).show();
//                    Intent intent = new Intent(mContext, MyDenglu.class);
//                    mContext.startActivityForResult(intent,1);
//                }
//            }
//        });
//        rl_user_history.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(readLogStatus()){
//                    //跳转到设置界面
//                }else{
//                    //未登录跳转到登陆界面
//                    Toast.makeText(mContext,"您还未登录，请先登录",Toast.LENGTH_SHORT).show();
//                    Intent intent = new Intent(mContext, MyDenglu.class);
//                    mContext.startActivityForResult(intent,1);
//                }
//            }
//        });
//
//
//    }
//
//    /*
//    * 登陆成功后设置我的界面*/
//    private void setLoginParams(boolean isLogin) {
//        if(isLogin){
//            tv_user_name.setText(AnalysisUtils.readLoginUserName(mContext));
//        }else {
//            tv_user_name.setText("点击登录");
//        }
//    }
//    /*
//    * 获取当前在导航栏上方显示对应的View*/
////    public View getView(){
//////        getViewif()
////    }
//
//    private boolean readLogStatus() {
//        SharedPreferences loginInfo = getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
//        boolean isLogin = loginInfo.getBoolean("isLogin", false);
//        return isLogin;
//    }
    private LayoutInflater mInflater;
    private Activity mContext;
    private View mCurrentView;
    private LinearLayout ll_head;
    public ImageView iv_head_icon;
    private RelativeLayout rl_course_hisstory;
    private RelativeLayout rl_user_history;
    private TextView tv_user_name;

    public myinfo(Activity context){
        mContext=context;
        //为之后将layout转化为view时用
        mInflater =LayoutInflater.from(mContext);
    }
    private void createView(){
        initView();
    }
    /*
    * 获取界面控件*/
    private void initView() {
        //设置布局文件
       mCurrentView = mInflater.inflate(R.layout.activity_myinfo,null);
        ll_head = mCurrentView.findViewById(R.id.ll_head);
        iv_head_icon = mCurrentView.findViewById(R.id.iv_head_icon);
        rl_course_hisstory = mCurrentView.findViewById(R.id.rl_course_history);
        rl_user_history = mCurrentView.findViewById(R.id.rl_user_history);
        tv_user_name = mCurrentView.findViewById(R.id.tv_user_name);
        mCurrentView.setVisibility(View.VISIBLE);
        setLogiinParams(readLoginStatus());//设置登录时界面控件的状态
        ll_head.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断是否已经登陆
                if(readLoginStatus()){
                    //已经登录跳转到个人资料界面
                    Intent intent = new Intent(mContext, user_Info.class);
                    mContext.startActivity(intent);
                }else{
                    //未登录跳转到界面
                    Intent intent = new Intent(mContext, MyDenglu.class);
                    mContext.startActivityForResult(intent,1);
                }
            }
        });
        rl_course_hisstory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(readLoginStatus()){
                    //跳转到播放记录页面
                }else{
                    Toast.makeText(mContext, "您还未登录", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(mContext, MyDenglu.class);
                    mContext.startActivityForResult(intent,1);
                }
            }
        });
        rl_user_history.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(readLoginStatus()){
                    //跳转到设置界面
                    Intent intent = new Intent(mContext, setting.class);
                    mContext.startActivityForResult(intent,1);
                }else{
                    Toast.makeText(mContext, "您还未登录", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(mContext, MyDenglu.class);
                    mContext.startActivityForResult(intent,1);
                }
            }
        });

    }
    /*
    * 登陆成功后设置我的界面*/

    void setLogiinParams(boolean readLoginStatus) {
        if(readLoginStatus){
            tv_user_name.setText(AnalysisUtils.readLoginUserName(mContext));
        }else{
            tv_user_name.setText("点击登录");
        }
    }
    /*
    * 获取当前导航栏上相对应的View*/
    public View getView(){
        if (mCurrentView==null){
            createView();
        }
        return mCurrentView;
    }
    /*
    * 显示当前导航栏上方所对应的view页面*/
    public void showView(){
        if(mCurrentView==null){
            createView();

        }
        mCurrentView.setVisibility(View.VISIBLE);

    }
    /*
    * 读取登录状态*/
    private boolean readLoginStatus() {
        SharedPreferences loginInfo = mContext.getSharedPreferences("loginInfo", Context.MODE_PRIVATE);
        boolean isLogin = loginInfo.getBoolean("isLogin", false);
        return isLogin;
    }


}